home *** CD-ROM | disk | FTP | other *** search
- unit RoundU;
-
- interface
-
- uses
- WinProcs, WinTypes, Messages, SysUtils, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls;
-
- type
- TForm1 = class(TForm)
- Button1: TButton;
- Label1: TLabel;
- Button2: TButton;
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.Button1Click(Sender: TObject);
- var
- AFloat: Extended;
- AnInt: Longint;
- begin
- AFloat := StrToFloat(
- InputBox('Rounding Test', 'Enter a floating point number', '2.5'));
- AnInt := Round(AFloat);
- Label1.Caption := Format('Round(%f) = %d', [AFloat, AnInt])
- end;
-
- procedure TForm1.Button2Click(Sender: TObject);
- var
- AFloat: Extended;
- AnInt: Longint;
- begin
- AFloat := StrToFloat(
- InputBox('Rounding Test', 'Enter a floating point number', '2.5'));
- asm
- { Push AFloat onto co-processor stack }
- FLD AFloat
- { Round float to an integer }
- FRNDINT
- { Pop integer into AnInt }
- FISTP AnInt
- { Ensure co-pro ops are complete before proceeding }
- FWAIT
- end;
- Label1.Caption := Format('Round(%f) = %d', [AFloat, AnInt])
- end;
-
- end.
-